package com.medical.Service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.medical.DTO.MedicalReportsDTO;
import com.medical.DTO.MedicalReportsPageDTO;
import com.medical.Mapper.MedicalReportsMapper;
import com.medical.Service.MedicalReportsService;
import com.medical.VO.MedicalReportsVO;
import com.medical.result.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class MedicalReportsServiceImpl implements MedicalReportsService {
    @Autowired
    private MedicalReportsMapper medicalReportsMapper;

    /**
     * 添加医疗报告
     *
     * @param medicalReportsDTO
     * @return
     */
    @Override
    public void addMedicalReports(MedicalReportsDTO medicalReportsDTO) {
        medicalReportsDTO.setCreateDate(LocalDateTime.now());
        medicalReportsMapper.insert(medicalReportsDTO);
    }

    /**
     * 删除医疗报告
     *
     * @param ids
     */
    @Override
    public void deleteMedicalReports(List<Integer> ids) {
        medicalReportsMapper.deleteMedicalReports(ids);
    }

    /**
     * 修改医疗报告
     *
     * @param medicalReportsDTO
     */
    @Override
    public void updateMedicalReports(MedicalReportsDTO medicalReportsDTO) {
        medicalReportsMapper.updateMedicalReports(medicalReportsDTO);
    }

    @Override
    public PageResult page(MedicalReportsPageDTO medicalReportsPageDTO) {
        PageHelper.startPage(medicalReportsPageDTO.getPage(), medicalReportsPageDTO.getPageSize());
        //Page<MedicalReportsVO> page = medicalReportsMapper.selectPage(medicalReportsPageDTO);
        List<MedicalReportsVO> pageList = medicalReportsMapper.selectPage(medicalReportsPageDTO);
        Page<MedicalReportsVO> page = (Page<MedicalReportsVO>) pageList;


        PageResult pageResult = new PageResult(page.getTotal(), page.getResult());
        return pageResult;
    }
}
